<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>预测结果 - 河域分割系统</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <div class="container">
            <a class="navbar-brand" href="{{ url_for('index') }}">河域分割系统</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('index') }}">首页</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('dashboard') }}">仪表板</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('data.my_data') }}">我的数据</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('data.upload') }}">上传数据</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('analysis.time_series_analysis') }}">时间分析</a>
                    </li>
                </ul>
                <ul class="navbar-nav">
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button" data-bs-toggle="dropdown">
                            <i class="bi bi-person-circle"></i> {{ current_user.username }}
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end">
                            <li><a class="dropdown-item" href="#">个人资料</a></li>
                            <li><a class="dropdown-item" href="#">设置</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="{{ url_for('auth.logout') }}">退出登录</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <!-- 主内容 -->
    <div class="container my-4">
        <div class="row mb-4">
            <div class="col-md-8">
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="{{ url_for('data.my_data') }}">我的数据</a></li>
                        <li class="breadcrumb-item"><a href="{{ url_for('data.image_detail', image_id=image.id) }}">{{ image.filename.split('_', 1)[1] }}</a></li>
                        <li class="breadcrumb-item active">预测结果</li>
                    </ol>
                </nav>
                <h2>预测结果</h2>
                <p class="text-muted">使用 <span class="badge bg-primary">{{ prediction.model_name }}</span> 模型的分割结果</p>
            </div>
            <div class="col-md-4 text-end">
                <a href="{{ url_for('data.image_detail', image_id=image.id) }}" class="btn btn-outline-secondary">
                    <i class="bi bi-arrow-left"></i> 返回数据详情
                </a>
            </div>
        </div>

        <!-- 结果展示 -->
        <div class="row mb-4">
            <div class="col-md-6 mb-4">
                <div class="card h-100">
                    <div class="card-header">
                        <h5 class="mb-0">原始图像</h5>
                    </div>
                    <div class="card-body text-center">
                        <img src="/uploads/{{ image.filename }}" class="img-fluid" alt="原始图像" style="max-height: 400px;">
                    </div>
                </div>
            </div>
            <div class="col-md-6 mb-4">
                <div class="card h-100">
                    <div class="card-header">
                        <h5 class="mb-0">分割结果</h5>
                    </div>
                    <div class="card-body text-center">
                        <img src="{{ result_url }}" class="img-fluid" alt="分割结果" style="max-height: 400px;">
                    </div>
                </div>
            </div>
        </div>

        <!-- 分析结果 -->
        <div class="row mb-4">
            <div class="col-md-6 mb-4">
                <div class="card h-100">
                    <div class="card-header">
                        <h5 class="mb-0">水域统计</h5>
                    </div>
                    <div class="card-body">
                        <div class="mb-3">
                            <label class="form-label">水域面积占比</label>
                            <div class="progress" style="height: 25px;">
                                <div class="progress-bar bg-primary" role="progressbar" 
                                     style="width: {{ prediction.water_area * 100 }}%;" 
                                     aria-valuenow="{{ prediction.water_area * 100 }}" 
                                     aria-valuemin="0" 
                                     aria-valuemax="100">
                                    {{ "%.2f"|format(prediction.water_area * 100) }}%
                                </div>
                            </div>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">水域面积</label>
                            <p class="mb-0">{{ "%.2f"|format(prediction.water_area * 100) }} 平方公里</p>
                        </div>
                        <div>
                            <label class="form-label">预测时间</label>
                            <p class="mb-0">{{ prediction.prediction_date.strftime('%Y-%m-%d %H:%M') }}</p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-6 mb-4">
                <div class="card h-100">
                    <div class="card-header">
                        <h5 class="mb-0">评估指标</h5>
                    </div>
                    <div class="card-body">
                        {% if prediction.iou_score %}
                        <div class="mb-3">
                            <label class="form-label">IoU 指标</label>
                            <div class="progress" style="height: 25px;">
                                <div class="progress-bar bg-success" role="progressbar" style="width: {{ prediction.iou_score * 100 }}%;" 
                                     aria-valuenow="{{ prediction.iou_score * 100 }}" aria-valuemin="0" aria-valuemax="100">
                                    {{ "%.2f"|format(prediction.iou_score * 100) }}%
                                </div>
                            </div>
                        </div>
                        {% endif %}

                        {% if prediction.f1_score %}
                        <div class="mb-3">
                            <label class="form-label">F1 分数</label>
                            <div class="progress" style="height: 25px;">
                                <div class="progress-bar bg-info" role="progressbar" style="width: {{ prediction.f1_score * 100 }}%;" 
                                     aria-valuenow="{{ prediction.f1_score * 100 }}" aria-valuemin="0" aria-valuemax="100">
                                    {{ "%.2f"|format(prediction.f1_score * 100) }}%
                                </div>
                            </div>
                        </div>
                        {% endif %}

                        {% if not prediction.iou_score and not prediction.f1_score %}
                        <div class="alert alert-info">
                            <p class="mb-0">暂无评估指标，需要地面真值图进行对比评估。</p>
                        </div>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>

        <!-- 操作按钮 -->
        <div class="row mb-4">
            <div class="col-12">
                <div class="d-flex justify-content-between">
                    <a href="{{ url_for('prediction.select_model', image_id=image.id) }}" class="btn btn-primary">
                        <i class="bi bi-arrow-repeat"></i> 使用其他模型
                    </a>
                    <a href="{{ url_for('analysis.area_analysis', prediction_id=prediction.id) }}" class="btn btn-success">
                        <i class="bi bi-graph-up"></i> 深入分析
                    </a>
                    <a href="{{ result_url }}" class="btn btn-outline-secondary" download>
                        <i class="bi bi-download"></i> 下载结果图像
                    </a>
                </div>
            </div>
        </div>
    </div>

    <!-- 页脚 -->
    <footer class="bg-dark text-white py-4 mt-5">
        <div class="container">
            <div class="row">
                <div class="col-md-6">
                    <h5>河域分割系统</h5>
                    <p>基于深度学习的河域分割与分析平台</p>
                </div>
                <div class="col-md-3">
                    <h5>链接</h5>
                    <ul class="list-unstyled">
                        <li><a href="{{ url_for('index') }}" class="text-white">首页</a></li>
                        <li><a href="{{ url_for('dashboard') }}" class="text-white">仪表板</a></li>
                        <li><a href="{{ url_for('data.my_data') }}" class="text-white">我的数据</a></li>
                    </ul>
                </div>
                <div class="col-md-3">
                    <h5>账户</h5>
                    <ul class="list-unstyled">
                        <li><a href="#" class="text-white">个人资料</a></li>
                        <li><a href="#" class="text-white">设置</a></li>
                        <li><a href="{{ url_for('auth.logout') }}" class="text-white">退出登录</a></li>
                    </ul>
                </div>
            </div>
            <hr>
            <div class="text-center">
                <p>&copy; 2023 河域分割系统. 保留所有权利.</p>
            </div>
        </div>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html> 